package com.lh.common.handler;

import com.lh.common.exception.LoginErrorException;
import com.lh.common.exception.SendCodeException;
import com.lh.common.exception.ServiceException;
import com.lh.common.result.Result;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @ClassName：ServiceExceptionHandler
 * @Author: LeiHao
 * @Date: 2024/8/9 9:54
 * @Description: 异常捕获器
 */
@RestControllerAdvice
public class ServiceExceptionHandler {
    @ExceptionHandler(LoginErrorException.class)
    public Result loginErrorException(LoginErrorException e) {
        return Result.error(e.getMessage());
    }
    @ExceptionHandler(ServiceException.class)
    public Result serviceException(ServiceException e) {
        return Result.error(e.getMessage());
    }
    @ExceptionHandler(SendCodeException.class)
    public Result sendCodeException(SendCodeException e) {
        return Result.error(e.getMessage());
    }
    @ExceptionHandler(RuntimeException.class)
    public Result runtimeException(RuntimeException e) {
        return Result.error(e.getMessage());
    }
    @ExceptionHandler(Exception.class)
    public Result exception(Exception e) {
        return Result.error(e.getMessage());
    }
}
